


import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:test_flutter/common/style/common_style.dart';
import 'package:test_flutter/page/dynamic_page.dart';
import 'package:test_flutter/page/home_drawer_widget.dart';
import 'package:test_flutter/page/trend_page.dart';
import 'package:test_flutter/page/user_page.dart';

/// 主页面
/// 三种方式设置底部导航栏
/// 1、TabBar+TabBarView
/// 2、BottomNavigationBar+BottomNavigationBarItem
/// 3、自定义BottomAppBar或自定义绘制布局
class HomePage extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return _HomePage();
  }
}

class _HomePage extends State<HomePage> with SingleTickerProviderStateMixin {

  int currentIndex = 0;
  late TabController _tabController;
  List tabs = ["动态", "趋势", "我的"];
  List icons = [Icons.camera, Icons.timeline, Icons.person];
  List<BottomNavigationBarItem> bottoms = [
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.calendar_today),
        label: "动态1",
        backgroundColor: UIColors.common_color_black),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.arrow_up_right_square_fill),
        label: "趋势2",
        backgroundColor: UIColors.common_color_black),
    BottomNavigationBarItem(
        icon: Icon(CupertinoIcons.person),
        label: "我的3",
        backgroundColor: UIColors.common_color_black),
  ];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(vsync: this, length: bottoms.length);
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> pages = [DynamicPage(), TrendPage(),
      UserPage()];
    return Scaffold(
      appBar: AppBar(
        backgroundColor: UIColors.common_color_black,
        title: Text('CZGithubAppFlutter'),
        // ignore: missing_return
        leading: Builder(builder: (context) {
          return IconButton(
            icon: Icon(Icons.view_headline, color: Colors.white), //自定义图标
            onPressed: () {
              // 打开抽屉菜单
              Scaffold.of(context).openDrawer();
            },
          );
        },),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.search),
            onPressed: () =>
            {
              print("开始搜索")
            },
          ),
        ],
        bottom: TabBar(
          tabs: tabs.map((e) =>
              Tab(text: e, icon: Icon(icons[tabs.indexOf(e)]),)).toList(),
          controller: _tabController,
        ),
      ),
      // bottomNavigationBar: BottomNavigationBar(
      //   type: BottomNavigationBarType.fixed,
      //   items: bottoms,
      //   currentIndex: currentIndex,
      //   onTap: (index){
      //     setState(() {
      //       currentIndex = index;
      //     });
      //   },
      // ),
      drawer: HomeDrawerWidget(),
      body: TabBarView(
        controller: _tabController,
        children: pages,
      ),
     // bottomNavigationBar: BottomNavigationBar( /// 底部导航栏
     //   items: <BottomNavigationBarItem>[
     //     BottomNavigationBarItem(icon: Icon(Icons.camera, color: UIColors.common_color_white,), title: Text('动态', style: TextStyle(color: UIColors.common_color_white),)),
     //     BottomNavigationBarItem(icon: Icon(Icons.timeline, color: UIColors.common_color_white), title: Text('趋势', style: TextStyle(color: UIColors.common_color_white),)),
     //     BottomNavigationBarItem(icon: Icon(Icons.person, color: UIColors.common_color_white), title: Text('我的', style: TextStyle(color: UIColors.common_color_white),)),
     //   ],
     //   backgroundColor: UIColors.common_color_black,
     //   fixedColor: UIColors.common_color_blue,
     //   currentIndex: currentIndex,
     //   onTap: (index) {
     //     setState(() {
     //       currentIndex = index;
     //     });
     //   },
     // ),
    );
  }
}
